package com.day240701.controller;

import com.alibaba.fastjson2.JSON;
import com.day240701.util.MyEmailUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "TestEmailServlet", value = "/TestEmailServlet")
public class TestEmailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String Email = request.getParameter("yourEmail");
        String randomNum = request.getParameter("randomNum");

        String msg = "<strong>" + randomNum + "</strong>";
        boolean flag = MyEmailUtils.send("这是您的验证码", msg, Email);
        String str = JSON.toJSONString(flag);

        PrintWriter out = response.getWriter();
        out.println(str);
        out.flush();
        out.close();
    }
}
